package com.example.httpservlet;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/servletImplExample")
public class ServletImplExample implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
       System.out.println("ServletImplExample的init方法被执行了：初始化！");
    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("ServletImplExample的service方法被执行了：被调用了！");
        //获取PrintWriter的对象
        PrintWriter writer = servletResponse.getWriter();
        //调用println方法输出内容"Hello Servlet!"到页面上
        servletResponse.setContentType("text/html;charset=utf-8") ;
        writer.println("Hello Servlet!");
        writer.println("企业后端开发技术");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("ServletImplExample的destroy方法被执行了：销毁了！");
    }
}
